package com.woniuxy.amusementparkos.service.wyh.imp;

import java.util.List;

import org.apache.ibatis.javassist.expr.NewArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.woniuxy.amusementparkos.dao.wyh.Balance_ChangeDao;
import com.woniuxy.amusementparkos.entity.wyh.Balance_Change;
import com.woniuxy.amusementparkos.entity.wyh.PageBean;
import com.woniuxy.amusementparkos.service.wyh.Balance_ChangeService;

import java_cup.internal_error;

@Service
public class Balance_ChangeServiceImp implements Balance_ChangeService {
	
	@Autowired
	Balance_ChangeDao balance_ChangeDao;
	
	//新增balance——changge
	@Override
	public void addObject(Balance_Change balance_Change) {
		balance_ChangeDao.addObject(balance_Change);
		
	}
	
	//获取所有
	@Override
	public List<Balance_Change> getAll() {
		
		return balance_ChangeDao.getAll();
	}
	
	//根据腕带编号获取该腕带消费信息
	@Override
	public List<Balance_Change> getByInfoid(int info_id) {
		
		return balance_ChangeDao.getByInfoid(info_id);
	}
	
	//根据posid查询所有充值项
	@Override
	public List<Balance_Change> getAllByPosid(int pos_id) {
		
		return balance_ChangeDao.getAllByPosid(pos_id);
	}

	//根据infoid查询对应的账户变化pagebean;
	@Override
	public PageBean<Balance_Change> getPagebeanByInfoid(int info_id, Integer pageNum,Integer size) {
		
		//创建pagebean
		PageBean<Balance_Change> pageBean = new PageBean<Balance_Change>();
		//设置大小
		if(size==null) {
			size =10;
		}
		
		if(pageNum==null) {
			pageNum=1;
		}
		//查询该条件下的记录总数
		int countByInfoid = (int) balance_ChangeDao.getCountByInfoid(info_id);
		
		//查询数据
		List<Balance_Change> pagebeanByInfoid = balance_ChangeDao.getPagebeanByInfoid(info_id, (pageNum-1)*size, size);
		
		//设置分页bean
		//设置返回值
		pageBean.setBeanList(pagebeanByInfoid);
		//设置size大小
		pageBean.setPageSize(size);
		//设置记录总条数
		pageBean.setTotalRecord(countByInfoid);
		//设置当前页码
		pageBean.setPageIndex(pageNum);
		//设置开始和结束页码
		pageBean.setPageBeginAndPageEnd();
		//设置总页数
		pageBean.setTotalPage(pageBean.getTotalPage());
		
		
		return pageBean;
	}
	
	//根据pos_id和 充值类型charge_type获取当日合计总额。如果未查询到数据返回0
	@Override
	public double getTotalbyPos_idAndCharge_type(int pos_id, int charge_type) {
		double total=0;
		//如果没有数据，返回0；
		try {
			total = balance_ChangeDao.getTotalbyPos_idAndCharge_type(pos_id, charge_type);
		} catch (Exception e) {

			return total;
		}
		
		return total;
	}

}
